package com.yuanian.ecsplus.reflect;

import com.yuanian.businessobject.model.enums.bodefine.BOColumnDataTypeEnum;
import com.yuanian.businessobject.model.vo.base.BOAreaFieldSetupVO;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;

/**
 * ECS配置的字段
 */
public class EcsField {

    //真正的字段
    private Field field;

    //字段在ECS平台的配置
    private BOAreaFieldSetupVO boAreaFieldSetupVO;

    public EcsField(Field field, BOAreaFieldSetupVO boAreaFieldSetupVO) {
        this.field = field;
        this.boAreaFieldSetupVO = boAreaFieldSetupVO;
    }

    public EcsField(Field field) {
        this.field = field;
    }

    public Field getField() {
        return field;
    }

    public BOAreaFieldSetupVO getBoAreaFieldSetupVO() {
        return boAreaFieldSetupVO;
    }

    public boolean isSysField() {
        return boAreaFieldSetupVO.getIsSys();
    }

    public BOColumnDataTypeEnum getDataType() {
        return boAreaFieldSetupVO.getDataType();
    }

    public boolean isEcsField() {
        return boAreaFieldSetupVO != null;
    }

    public void setBoAreaFieldSetupVO(BOAreaFieldSetupVO boAreaFieldSetupVO) {
        this.boAreaFieldSetupVO = boAreaFieldSetupVO;
    }

    public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) {
        return this.field.isAnnotationPresent(annotationClass);
    }

    public String getName() {
        return this.field.getName();
    }

    public Class<?> getType() {
        return this.field.getType();
    }

    public void set(Object obj, Object value) throws IllegalAccessException {
        this.field.set(obj, value);
    }
}
